package com.example.demo.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.demo.model.AccessToken;
import com.example.demo.repository.AccessTokenRepository;
import com.example.demo.service.AccessTokenService;

@Service
public class AccessTokenServiceImpl extends BaseServiceImpl<AccessToken> implements AccessTokenService {

	@Autowired
	private AccessTokenRepository accessTokenRepository;
	
	@Override
	public void create(AccessToken entity) {
		//删除旧token然后保存新token
		accessTokenRepository.deleteByUsername(entity.getUsername());
		accessTokenRepository.save(entity);
	}

	@Override
	public AccessToken findByToken(String token) {
		return accessTokenRepository.findByAccessToken(token);
	}

	@Override
	public void deleteByToken(String token) {
		accessTokenRepository.deleteByAccessToken(token);
	}

	

}
